/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.bid.service.cacheplugins  
 */
package com.apache.bid.service.cacheplugins;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.bid.common.WbdToolsUtil;
import com.apache.bid.common.cache.BidCacheFactory;
import com.apache.bid.entity.BidApply;
import com.apache.bid.manager.BidApplyManager;
import com.apache.cache.util.Validator;

/**
 * description:  添加申请记录信息
 * @author Hou Dayu 创建时间：2016-3-28  
 * 
 */
public class SaveBidapplyPluginImpl implements PluginConnector {

	private BidApplyManager bidApplyManager;

	/**
	 * TODO 简单描述该方法的实现功能（可选）.  
	 * @see com.zbxsoft.api.manager.PluginConnector#execute(com.zbxsoft.api.vo.ParamsVo)  
	 */
	public Object execute(ParamsVo param) throws Exception {
		BidApply apply = new BidApply();
		apply = (BidApply) WbdToolsUtil.getInstance().convert2Bean(param.getParams(), apply);
		ResultEntity entity = new ResultEntity();
		if (Validator.isNull(apply.getUserName())) {
			entity.setResult("false");
			entity.setMessage("缺少方法参数,方法执行失败");
		} else {
			ParamsVo<BidApply> vo = new ParamsVo<BidApply>();
			vo.setObj(apply);
			String applyId = bidApplyManager.saveInfo(vo);
			if (Validator.isNotNull(applyId)) {
				BidCacheFactory.getInstance().getCacheManager("apply").createCacheObject(apply);
			}
			entity.setResult("true");
			entity.setMessage("信息保存成功");
			entity.setEntity(applyId);
		}
		return entity;
	}

	public void setBidApplyManager(BidApplyManager bidApplyManager) {
		this.bidApplyManager = bidApplyManager;
	}

}
